<?php
/**
 * 商品API验证器
 * @author 王勇程 <laughskydragon@qq.com>
 */

namespace app\api\validate;

use think\Validate;

class Product extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'product_id' => 'require|integer|gt:0',
        'keyword' => 'require|length:1,50',
        'category_id' => 'integer|egt:0',
        'page' => 'integer|egt:1',
        'limit' => 'integer|between:1,100',
        'days' => 'integer|in:7,30,90,365,1095',
    ];
    
    /**
     * 验证消息
     */
    protected $message = [
        'product_id.require' => '商品ID不能为空',
        'product_id.integer' => '商品ID必须为整数',
        'product_id.gt' => '商品ID必须大于0',
        'keyword.require' => '搜索关键词不能为空',
        'keyword.length' => '搜索关键词长度必须在1-50个字符之间',
        'category_id.integer' => '分类ID必须为整数',
        'category_id.egt' => '分类ID必须大于等于0',
        'page.integer' => '页码必须为整数',
        'page.egt' => '页码必须大于等于1',
        'limit.integer' => '每页数量必须为整数',
        'limit.between' => '每页数量必须在1-100之间',
        'days.integer' => '天数必须为整数',
        'days.in' => '天数只能是7、30、90、365、1095中的一个',
    ];
    
    /**
     * 验证场景
     */
    protected $scene = [
        'detail' => ['product_id'],
        'history' => ['product_id', 'days'],
        'search' => ['keyword'],
    ];
}